// This file copied from pkg/postgres/schema/ before making any changes to the storage.VulnerabilityRequest

package oldschema

import (
	"reflect"
	"time"

	"github.com/lib/pq"
	v1 "github.com/stackrox/rox/generated/api/v1"
	"github.com/stackrox/rox/generated/storage"
	"github.com/stackrox/rox/pkg/postgres"
	"github.com/stackrox/rox/pkg/postgres/walker"
	"github.com/stackrox/rox/pkg/sac/resources"
	"github.com/stackrox/rox/pkg/search"
)

var (
	// CreateTableVulnerabilityRequestsStmt holds the create statement for table `vulnerability_requests`.
	CreateTableVulnerabilityRequestsStmt = &postgres.CreateStmts{
		GormModel: (*VulnerabilityRequests)(nil),
		Children: []*postgres.CreateStmts{
			{
				GormModel: (*VulnerabilityRequestsApprovers)(nil),
				Children:  []*postgres.CreateStmts{},
			},
			{
				GormModel: (*VulnerabilityRequestsComments)(nil),
				Children:  []*postgres.CreateStmts{},
			},
		},
	}

	// VulnerabilityRequestsSchema is the go schema for table `vulnerability_requests`.
	VulnerabilityRequestsSchema = func() *walker.Schema {
		schema := walker.Walk(reflect.TypeOf((*storage.VulnerabilityRequest)(nil)), "vulnerability_requests")
		schema.SetOptionsMap(search.Walk(v1.SearchCategory_VULN_REQUEST, "vulnerabilityrequest", (*storage.VulnerabilityRequest)(nil)))
		schema.ScopingResource = resources.VulnerabilityRequest
		return schema
	}()
)

const (
	// VulnerabilityRequestsTableName specifies the name of the table in postgres.
	VulnerabilityRequestsTableName = "vulnerability_requests"
	// VulnerabilityRequestsApproversTableName specifies the name of the table in postgres.
	VulnerabilityRequestsApproversTableName = "vulnerability_requests_approvers"
	// VulnerabilityRequestsCommentsTableName specifies the name of the table in postgres.
	VulnerabilityRequestsCommentsTableName = "vulnerability_requests_comments"
)

// VulnerabilityRequests holds the Gorm model for Postgres table `vulnerability_requests`.
type VulnerabilityRequests struct {
	ID                                string                           `gorm:"column:id;type:varchar;primaryKey"`
	TargetState                       storage.VulnerabilityState       `gorm:"column:targetstate;type:integer"`
	Status                            storage.RequestStatus            `gorm:"column:status;type:integer"`
	Expired                           bool                             `gorm:"column:expired;type:bool"`
	RequestorName                     string                           `gorm:"column:requestor_name;type:varchar"`
	CreatedAt                         *time.Time                       `gorm:"column:createdat;type:timestamp"`
	LastUpdated                       *time.Time                       `gorm:"column:lastupdated;type:timestamp"`
	DeferralReqExpiryExpiresWhenFixed bool                             `gorm:"column:deferralreq_expiry_expireswhenfixed;type:bool"`
	DeferralReqExpiryExpiresOn        *time.Time                       `gorm:"column:deferralreq_expiry_expireson;type:timestamp"`
	DeferralReqExpiryExpiryType       storage.RequestExpiry_ExpiryType `gorm:"column:deferralreq_expiry_expirytype;type:integer"`
	CvesCves                          *pq.StringArray                  `gorm:"column:cves_cves;type:text[]"`
	Serialized                        []byte                           `gorm:"column:serialized;type:bytea"`
}

// VulnerabilityRequestsApprovers holds the Gorm model for Postgres table `vulnerability_requests_approvers`.
type VulnerabilityRequestsApprovers struct {
	VulnerabilityRequestsID  string                `gorm:"column:vulnerability_requests_id;type:varchar;primaryKey"`
	Idx                      int                   `gorm:"column:idx;type:integer;primaryKey;index:vulnerabilityrequestsapprovers_idx,type:btree"`
	Name                     string                `gorm:"column:name;type:varchar"`
	VulnerabilityRequestsRef VulnerabilityRequests `gorm:"foreignKey:vulnerability_requests_id;references:id;belongsTo;constraint:OnDelete:CASCADE"`
}

// VulnerabilityRequestsComments holds the Gorm model for Postgres table `vulnerability_requests_comments`.
type VulnerabilityRequestsComments struct {
	VulnerabilityRequestsID  string                `gorm:"column:vulnerability_requests_id;type:varchar;primaryKey"`
	Idx                      int                   `gorm:"column:idx;type:integer;primaryKey;index:vulnerabilityrequestscomments_idx,type:btree"`
	UserName                 string                `gorm:"column:user_name;type:varchar"`
	VulnerabilityRequestsRef VulnerabilityRequests `gorm:"foreignKey:vulnerability_requests_id;references:id;belongsTo;constraint:OnDelete:CASCADE"`
}
